Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding azdoPrRepoName as metadata in FluxCD alert #74

Closed
wants to merge 3 commits into from
Closed

Adding azdoPrRepoName as metadata in FluxCD alert #74

wants to merge 3 commits into from

Conversation

cyberjpb1
Copy link

@cyberjpb1 cyberjpb1 commented Aug 20, 2024

I added a metadata in the alert definition of the gitops-connector to be able to identify the name of the repo corresponding to the PR. This modification allowed me to support my scenario where I have a manifest repo per application.

spec:
eventMetadata:
  azdoPrRepoName: WebApp1

I should mention that I don't know the Python language and I went with the logic of the existing code so don't judge my code too harshly.

apiVersion: notification.toolkit.fluxcd.io/v1beta2
kind: Provider
metadata:
  name: webappexemple-gitops-connector
  namespace: flux-system
spec:
  type: generic
  address: http://gitops-connector:8080/gitopsphase
---
apiVersion: notification.toolkit.fluxcd.io/v1beta2
kind: Alert
metadata:
  name: webappexemple-gitops-connector
  namespace: flux-system
spec:
  eventMetadata:
    azdoPrRepoName: WebApp1
  eventSeverity: info
  providerRef:
    name: webappexemple-gitops-connector
  eventSources:
    - kind: GitRepository
      name: webappexemple-source
    - kind: Kustomization
      name: webappexemple-kustomization

logging.debug(f'azdoPrRepoName: {repo_n}')
if repo_n != '':
self._gitops_operator.callback_url = self._git_repository.set_git_repository(repo_n)
self._cicd_orchestrator.set_git_repository(repo_n)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GitOps connector instance is shared across threads. It is very possible that another thread, initiated by an alert configured for the different application/repo, will override these self settings. So the message from thread 1 will go to the repo from thread 2.

Copy link
Collaborator

@eedorenko eedorenko Aug 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides forwarding the alerts to AZDO, GitOps connector detects abandoned/rejected PRs to the GitOps repo and notifies the agentless waiting task to fail, so the whole promotional flow gets failed. This logic is implemented on top of having a single repo.

IMO, if we want to support multiple applications, we have the options:

  • Have an instance of GitOps Connector per application
  • Enhance the GitOps Connector to be configured with multiple repos (e.g. in config maps) and like you suggested, reference these repos in the alert definition

@cyberjpb1
Copy link
Author

Thanks for the review, so I'm closing the Pull Request.

@cyberjpb1 cyberjpb1 closed this Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants